
package com.jf.cloud.order.listener;

import cn.hutool.core.collection.CollectionUtil;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.order.service.OrderPreSaleInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zz
 * @date 2021/1/7
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.PRESALE_ORDER_CANAL_TOPIC,consumerGroup = RocketMqConstant.PRESALE_ORDER_CANAL_TOPIC)
public class PresaleOrderCanalConsumer implements RocketMQListener<List<Long>> {

    @Autowired
    private OrderPreSaleInfoService orderPreSaleInfoService;

    private static final Logger LOG = LoggerFactory.getLogger(PresaleOrderCanalConsumer.class);

    @Override
    public void onMessage(List<Long> orderIds) {
        LOG.info("取消预售订单回调开始... message: " + Json.toJsonString(orderIds));
        if (CollectionUtil.isEmpty(orderIds)) {
            return;
        }
        List<Long> canalOrderList = new ArrayList<>();
        // 取消订单，不用退回金额,但因为商家平台供应商收入了一笔，还需要进行结算
        orderPreSaleInfoService.handleBalanceTimeExpireOrder(orderIds, canalOrderList);
    }
}
